<?php

namespace App\Http\Controllers\Admin;

use App\Http\Filters\EquipmentFilter;
use App\Models\Equipment;
use App\Http\Requests\EquipmentRequest;
use App\Http\Resources\EquipmentResource;
use Illuminate\Http\Request;

class EquipmentController extends Controller
{
    public function index(EquipmentFilter $filter)
    {
        $equipments = Equipment::query()
            ->filter($filter)
            ->paginate();

        return $this->ok(EquipmentResource::collection($equipments));
    }

    public function create()
    {
        return $this->ok();
    }

    public function store(EquipmentRequest $request)
    {
        $inputs = $request->validated();
        $equipment = Equipment::create($inputs);

        return $this->created(EquipmentResource::make($equipment));
    }

    public function edit(Request $request, Equipment $equipment)
    {
        return $this->ok(EquipmentResource::make($equipment));
    }

    public function update(EquipmentRequest $request, Equipment $equipment)
    {
        $inputs = $request->validated();
        $equipment->update($inputs);

        return $this->created(EquipmentResource::make($equipment));
    }

    public function destroy(Equipment $equipment)
    {
        $equipment->delete();
        return $this->noContent();
    }
}
